/*
 * @Description: 有效的括号
 * @FilePath: \网易云音乐e:\CSS+HTML+JS+\学习笔记\代码测试\算法\leetcode\20.有效的括号.js
 */ 
/*
 * @lc app=leetcode.cn id=20 lang=javascript
 *
 * [20] 有效的括号
 */

// @lc code=start
/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function(s) {
    let stack = [];
    for(let i = 0, len = s.length; i < len; i++) {
        if(s[i] == '{' || s[i] == '[' || s[i] == '(') {
            stack.push(s[i]);
        } else {
            if(s[i] === '}') {
                stack[stack.length-1] == '{' ? stack.pop() : stack.push(s[i]);
            }
            if(s[i] === ']') {
                stack[stack.length-1] == '[' ? stack.pop() : stack.push(s[i]);
            }
            if(s[i] === ')') {
                stack[stack.length-1] == '(' ? stack.pop() : stack.push(s[i]);
            }
        }
    }
    console.log(stack);
    return (stack.length != 0 ? false : true);
};
let res = isValid("(])");
console.log(res);
// @lc code=end

